/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// peditbox.hpp - Editable multi-line text box class definition.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software 
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGEDITBOX_
#define _PEGEDITBOX_

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
struct CURSOR_POS 
{
    void Set(PEGINT InX, PEGINT InY)
    {
        x = InX;
        y = InY;
    }

    PEGBOOL operator != (const CURSOR_POS &InPoint) const 
    {
        if (x != InPoint.x || y != InPoint.y)
        {
            return TRUE;
        }
        return FALSE;
    }
    PEGBOOL operator == (const CURSOR_POS &InPoint) const
    {
        if (x == InPoint.x && y == InPoint.y)
        {
            return TRUE;
        }
        return FALSE;
    }

    PEGINT x;
    PEGINT y;

};


/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegEditBox : public PegTextBox
{
    public:

        PegEditBox(const PegRect &Rect, PEGUINT StringId = 0,
                   PEGUSHORT Id = 0,
                   PEGULONG Style = FF_RECESSED|EF_EDIT|EF_WRAP,
                   PEGUINT MaxChars = 1000);

        PegEditBox(const PEGCHAR *pText, const PegRect &Rect, 
                   PEGUSHORT Id = 0,
                   PEGULONG Style = TT_COPY|FF_RECESSED|EF_EDIT|EF_WRAP,
                   PEGUINT MaxChars = 1000);

        virtual void Append(PEGINT StringId);
        virtual void Append(const PEGCHAR *pText);

        void CopyToScratchPad(void);

        virtual void DataSet(PEGUINT StringId);
        virtual void DataSet(const PEGCHAR *pText);

        void DeleteMarkedText(void);
        virtual void Draw(const PegRect &Invalid);
        CURSOR_POS GetCursorRowCol(void) {return mCursor;}
        void HomeCursor(void);
        PEGBOOL InEditMode(void) {return State.mEditMode;}

        virtual void InsertCharAtCursor(PEGUINT Key);
        virtual PEGINT Message(const PegMessage &Mesg);
        void PasteFromScratchPad(void);
        void SetCursorRowCol(PEGINT Index);

    protected:

        virtual PEGBOOL AutoScrollLeft(void);
        virtual PEGBOOL AutoScrollUp(void);
        virtual PEGBOOL CheckAutoScrollDown(void);
        virtual PEGBOOL CheckAutoScrollRight(void);

       #ifdef PEG_KEYBOARD_SUPPORT
        virtual PEGBOOL CheckControlKey(PEGUINT Key, PEGINT Ctrl);
       #endif

        virtual void CheckMarkMove(void);
        virtual void DrawCharAtCursor(PEGINT Key);
        virtual void DrawCursor(void);
        virtual void DrawMarkedText(PEGINT Line, PegPoint PutPoint);
        virtual void DrawOneLine(PEGINT Line);
        virtual void DrawSelectText(PEGINT Line, PEGINT First, PEGINT Last,
                                    PEGBOOL Sel);
        virtual void DrawTextLine(PEGINT Line, PegPoint PutPoint, 
                                  PEGBOOL Fill = FALSE);

        virtual void ExitEditMode(void);
        virtual const PEGCHAR *GetCharAtCursor(void);
        virtual void GetCursorPointFromRowCol(void);
        virtual void GetCursorRowColFromClick(PegPoint Where);
        virtual void GetMarkStartAndEnd(CURSOR_POS *pStartMark, 
                                        CURSOR_POS *pEndMark);

        virtual PEGBOOL InsertKey(PEGUINT Key);
        void NewEditDataSet(void);
        virtual void RemoveCharAtCursor(PEGBOOL BackSpace);
        virtual void RemoveCursor(void);
        virtual void ReplaceMarkedText(PEGUINT Key);
        virtual void SetCursorRowColFromIndex(PEGINT Index);


        CURSOR_POS  mCursor;       // row, col of cursor
        CURSOR_POS  mMarkAnchor;   // row, col position of mark anchor
        CURSOR_POS  mMarkEnd;      // row, col position of mark end
        PegPoint    mCursorPos;    // top, left pixel position of cursor

        struct 
        {
            PEGUINT mEditMode:1;
            PEGUINT mMarked:1;
            PEGUINT mMarkMode:1;
            PEGUINT mPointerSet:1;
        } State;
};

#endif



